package com.boot.hospital.score.core.service.impl;

import com.boot.hospital.score.core.service.ReviewService;
import com.boot.hospital.score.core.service.ScoreService;
import com.boot.hospital.score.dao.entity.Review;
import com.boot.hospital.score.dao.mapper.ExpertMapper;
import com.boot.hospital.score.dao.mapper.ReviewMapper;
import com.boot.hospital.score.dao.mapper.ScoreMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class ReviewServiceImpl implements ReviewService {

    @Resource
    private ReviewMapper reviewMapper;
    @Resource
    private ExpertMapper expertMapper;
    @Resource
    private ScoreMapper scoreMapper;

    @Override
    public List<Review> selectAll() {
        return reviewMapper.selectAll();
    }

    @Override
    public int insert(Review review) {
        return reviewMapper.insert(review);
    }

    @Override
    public int deleteReviewsByIds(List<Integer> reviewIds) {

        if (reviewMapper.deleteReviewsByIds(reviewIds) > 0
                && expertMapper.deleteExpertsByReviewIds(reviewIds) > 0
                && scoreMapper.deleteScoresByReviewIds(reviewIds) > 0) {
            return 1;
        }
        return 0;
    }
    @Override
    public int updateReview(Review review) {
        return reviewMapper.updateReview(review);
    }

    @Override
    public List<Review> selectByPageAndSearch(Map<String, Object> params) {
        return reviewMapper.selectByPageAndSearch(params);
    }

    @Override
    public List<Review> selectBySearch(String search) {
        return reviewMapper.selectBySearch(search);
    }

    @Override
    public Review selectById(Integer reviewId) {
        return reviewMapper.selectById(reviewId);
    }

}